﻿#ifndef __MilitaryRankByExploit_H__
#define __MilitaryRankByExploit_H__

#include "pch.h"
#include "cvsreader.h"
#include "config.h"
#include "noncopyable.h"

// generate by ProtoGen at date: 2017/4/24 20:51:18


class MilitaryRankByExploit : public CVSReader, public noncopyable
{
public:

	struct RowData
	{
		uint	MilitaryRank;
		string	Name;
		Sequence<uint, 2>	MilitaryExploit;
		vector<Sequence<uint, 2>>	Reward;
		string	Icon;
		string	ShowRange;
		string	RewardTips;

		void CopyFrom(RowData *pRowData)
		{
			this->MilitaryRank=pRowData->MilitaryRank;
			this->Name=pRowData->Name;
			this->MilitaryExploit=pRowData->MilitaryExploit;
			this->Reward=pRowData->Reward;
			this->Icon=pRowData->Icon;
			this->ShowRange=pRowData->ShowRange;
			this->RewardTips=pRowData->RewardTips;

		}
	};

	std::unordered_map<uint,int> MilitaryRank_Index;


        RowData *GetByMilitaryRank(const uint &key)
        {
            auto i = MilitaryRank_Index.find(key);
            return (i == MilitaryRank_Index.end()) ? NULL : Table[i->second];
        }
        

	virtual bool OnHeaderLine(char **Fields, int FieldCount)
	{
		const char *Headers[] = { "MilitaryRank", "Name", "MilitaryExploit", "Reward", "Icon", "ShowRange", "RewardTips",  };
		const int HeadersCount = sizeof(Headers)/sizeof(Headers[0]);
		//assert(FieldCount == HeadersCount);
		return MapColHeader(Headers, HeadersCount, Fields, FieldCount);
	}

	virtual bool OnCommentLine(char **Fields, int FieldCount)
	{
		return true;
	}

	void CopyFrom(MilitaryRankByExploit  *pSrcTable)
	{
		for (UINT32 i = 0; i< pSrcTable->Table.size(); i++)
		{
			RowData* pSrcRow = pSrcTable->Table[i];
           RowData *pDstRow = GetByMilitaryRank(pSrcRow->MilitaryRank);
           if(pDstRow != NULL)
           {
               pDstRow->CopyFrom(pSrcRow);
           }
           else
           {
               RowData* pNewRow = new RowData();
               pNewRow->CopyFrom(pSrcRow);
               Table.push_back(pNewRow);
               MilitaryRank_Index[pNewRow->MilitaryRank]=Table.size()-1;
           }

		}
	}

	virtual bool OnLine(char **Fields, int FieldCount)
	{
		RowData *pRow = new RowData();
		RowData &row = *pRow;
		m_ColNum = 0;

		if (!Parse(Fields[m_ColMap[0]], row.MilitaryRank)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[1]], row.Name)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[2]], row.MilitaryExploit)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[3]], row.Reward)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[4]], row.Icon)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[5]], row.ShowRange)) return false; ++m_ColNum;
		if (!Parse(Fields[m_ColMap[6]], row.RewardTips)) return false; ++m_ColNum;

		
		Table.push_back(pRow);

		MilitaryRank_Index[row.MilitaryRank] = Table.size()-1;


		return true;
	}

	~MilitaryRankByExploit ()
	{
		Clear();
	}

	void Clear()
	{
		for (UINT32 i = 0; i < Table.size(); ++i)
		{
			delete Table[i];
		}

		Table.clear();
	}

	std::vector<RowData*> Table;
};

#endif